{% extends "base.html" %}

{% block title %}{{ user.username }}'s Posts - Flask Database Demo{% endblock %}

{% block content %}
<h2>{{ user.username }}'s Posts</h2>

<div class="row">
    <div class="col-md-8">
        <div class="card mb-3">
            <div class="card-header">
                <h5>User Information</h5>
            </div>
            <div class="card-body">
                <p><strong>Username:</strong> {{ user.username }}</p>
                <p><strong>Email:</strong> {{ user.email }}</p>
                <p><strong>Member Since:</strong> {{ user.member_since.strftime('%Y-%m-%d') }}</p>
                <p><strong>Total Posts:</strong> {{ user.posts.count() }}</p>
            </div>
        </div>
        
        {% if posts %}
            <h4>Posts ({{ posts|length }})</h4>
            {% for post in posts %}
                <div class="card mb-2">
                    <div class="card-body">
                        <h5 class="card-title">{{ post.title }}</h5>
                        <p class="card-text">{{ post.body[:100] }}{% if post.body|length > 100 %}...{% endif %}</p>
                        <small class="text-muted">{{ post.timestamp.strftime('%Y-%m-%d %H:%M') }}</small>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <div class="alert alert-info">
                <p>{{ user.username }} has not created any posts yet.</p>
            </div>
        {% endif %}
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5>Navigation</h5>
            </div>
            <div class="card-body">
                <a href="{{ url_for('users') }}" class="btn btn-primary w-100 mb-2">All Users</a>
                <a href="{{ url_for('posts') }}" class="btn btn-primary w-100 mb-2">All Posts</a>
                <a href="{{ url_for('create_post') }}" class="btn btn-success w-100">Create Post</a>
            </div>
        </div>
    </div>
</div>

<div class="mt-3">
    <a href="{{ url_for('users') }}" class="btn btn-secondary">Back to Users</a>
</div>
{% endblock %}